package com.young.grpc.client;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import lombok.extern.slf4j.Slf4j;
import org.young.grpc.demo.ProductInfoGrpc;
import org.young.grpc.demo.ProductOuterClass;

/**
 * @description：
 * @author: yangyahui01
 * @date: 12/3/24 4:56 PM
 */
@Slf4j
public class GrpcClient {
    public static void main(String[] args) {
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("localhost", 50091).usePlaintext(true).build();

        ProductInfoGrpc.ProductInfoBlockingStub stub = ProductInfoGrpc.newBlockingStub(managedChannel);

        ProductOuterClass.Product req = ProductOuterClass.Product.newBuilder()
                .setId("1")
                .setPrice(100.0f)
                .setName("test-grpc")
                .setDescription("test-grpc")
                .build();

        ProductOuterClass.ProductId productId = stub.addProduct(req);

        log.info("productId.getValue:{}", productId.getValue());

        ProductOuterClass.Product product = stub.getProduct(ProductOuterClass.ProductId.newBuilder().setValue("99999").build());

        log.info("product:{}", product.toString());
    }
}
